package com.qf.utils;

/*
 *  @author Administrator
 *  @version V1.0
 *  @Project smartdeviceplatgorm
 *  @Package com.qf.utils
 *  @Description
 *  @Date2022/3/17 0017 17:48
 */

import com.qf.bean.SysUserInfo;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

public class SecurityUtils {
    public static SysUserInfo getLoginUser(){
        try {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
            return (SysUserInfo) request.getSession().getAttribute("user");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public static SysUserInfo getLoginUserWithTest() {
        SysUserInfo sysUserInfo=new SysUserInfo();
        sysUserInfo.setUsername("zhangsan");
        return sysUserInfo;
    }
}
